<?php
/**
 * Description of DepartmentMapper
 *
 /*
 * @author     Thibaut Cromphaut and Dimitry Dierickx
 * @copyright  Copyright (c) 2011 Safti-Kado
 */
class Application_Model_SubdepartmentMapper extends Ahs_Model_Mapper
{

    public function __construct(array $options = null)
    {
        parent::__construct($options);
        $this->DbTableName = 'Application_Model_DbTable_Subdepartments';
    }
    
    /**
     * Gebruiker met een bepaalde id ophalen
     * 
     * @param integer $id
     * @return Application_Model_Department
     */
    public function fetchById($id)
    {
        $row = $this->getDbTable()->fetchRow(array('subdepartments_id = ?' => $id));

        return $this->_toSubdepartment($row);
        //return $row['subdepartments_name'];
    }
    
    /**
     * Alle Users ophalen
     * 
     * @return array
     */
    public function fetchAll()
    {        
        $rows = $this->getDbTable()->fetchAll();        
        return $this->_toSubdepartments($rows);
        //return $this->getDbTable();
    }
    
    /**
     * @param Zend_Db_Table_Row_Abstract $row
     * @return Application_Model_Subdepartment 
     */
    private function _toSubdepartment(Zend_Db_Table_Row_Abstract $row = null)
    {
       $subdepartment = new Application_Model_Subdepartment();

        if ($row) {
            $subdepartment->Id         = $row['subdepartments_id'];
            $subdepartment->Name       = $row['subdepartments_name'];
            $subdepartment->Points     = $row['subdepartments_points'];
        }        
        return $subdepartment;
    }

    /**
     * @param Zend_Db_Table_Rowset_Abstract $rows
     * @return array
     */
    private function _toSubdepartments(Zend_Db_Table_Rowset_Abstract $rows = null)
    {
        $subdepartments = array();

        if ($rows) {
            foreach ($rows as $row) {
                $subdepartments[] = $this->_toSubdepartment($row);
            }
        }
        
        return $subdepartments;
    }

}